//
//  ViewController.swift
//  Rainy
//
//  Created by teddy on 4/22/16.
//  Copyright © 2016 teddy. All rights reserved.
//

import UIKit
import CoreLocation
import Alamofire
import LTMorphingLabel
import Spring
import NumberMorphView
import FillableLoaders


class ViewController: UIViewController, CLLocationManagerDelegate {
    
    @IBOutlet weak var addressLabel: UILabel!
    @IBOutlet weak var mainWeatherImage: UIImageView!
    @IBOutlet weak var mainWeatherText: UILabel!
    @IBOutlet weak var mainWeatherTemp: UILabel!
    
    // 全局变量 1
    var locateManage = CLLocationManager()
    var currentCoordinate:CLLocationCoordinate2D?
    // 全局变量 2
    var wholeLocation = TLocation()
    var wholeNow = TNow()
    var wholeThreeDays = Array<Tdaily>()
    
    // 全局变量 4
    var locationTimes = 0
    
    // 页面开始
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 定义通知
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.didBecomeActive), name: UIApplicationDidBecomeActiveNotification, object: nil)
        
        // location代理
        self.locateManage.delegate = self
        
        // 请求定位权限
        if self.locateManage.respondsToSelector(#selector(CLLocationManager.requestAlwaysAuthorization)) {
            self.locateManage.requestAlwaysAuthorization()
        }
        
        // 定位精准度
        self.locateManage.desiredAccuracy = kCLLocationAccuracyBest
        
        // 开始定位
        self.locateManage.startUpdatingLocation()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    // 接收通知
    func didBecomeActive() -> () {
        
        // 恢复所有的设置 (数据源)
        locationTimes = 0
        wholeLocation = TLocation()
        wholeNow = TNow()
        wholeThreeDays = Array<Tdaily>()
        
        // location代理
        self.locateManage.delegate = self
        
        // 请求定位权限
        if self.locateManage.respondsToSelector(#selector(CLLocationManager.requestAlwaysAuthorization)) {
            self.locateManage.requestAlwaysAuthorization()
        }
        
        // 定位精准度
        self.locateManage.desiredAccuracy = kCLLocationAccuracyBest
        
        // 开始定位
        self.locateManage.stopUpdatingLocation()
        self.locateManage.startUpdatingLocation()
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    // CLLocationManager定位代理方法
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        
        // 停止定位，节省电量，只获取一次定位
        if (locationTimes > 0) {
            manager.stopUpdatingLocation()
            return
        }
        if let newLoca = locations.last {
            
            locationTimes = locationTimes + 1
            
            CLGeocoder().reverseGeocodeLocation(newLoca, completionHandler: { (pms, err) -> Void in
                if let newCoordinate = pms?.last?.location?.coordinate {
                    // 设定当前位置信息
                    self.currentCoordinate = newCoordinate
                    //取得最后一个地标，地标中存储了详细的地址信息，注意：一个地名可能搜索出多个地址
                    let placemark:CLPlacemark = (pms?.last)!
                    let location = placemark.location;//位置
                    let addressInfo: String = String(Double((location?.coordinate.latitude)!)) + ":" + String(Double((location?.coordinate.longitude)!))
                    print (addressInfo)
                    
                    // 赋值地理信息给AppDelegate的全局变量
                    let app: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
                    app.locationString = addressInfo
                    
                    self.requestDataNow(addressInfo)
                    self.requestDataAll(addressInfo)
                    
                }
            })
        }
    }
    
    // 定位失败
    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        print (error.localizedDescription)
    }
    
    // view即将消失
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    // 显示时间
//    func displayTime() -> () {
//        
//        h1.fontColor = UIColor.grayColor()
//        h0.fontColor = UIColor.grayColor()
//        m1.fontColor = UIColor.grayColor()
//        m0.fontColor = UIColor.grayColor()
//        s1.fontColor = UIColor.grayColor()
//        s0.fontColor = UIColor.grayColor()
//        
//        h1.fontSize = 56
//        h0.fontSize = 56
//        m1.fontSize = 56
//        m0.fontSize = 56
//        s1.fontSize = 56
//        s0.fontSize = 56
//        
//        h1.interpolator = NumberMorphView.LinearInterpolator();
//        h0.interpolator = NumberMorphView.LinearInterpolator();
//        m1.interpolator = NumberMorphView.LinearInterpolator();
//        m0.interpolator = NumberMorphView.LinearInterpolator();
//        s1.interpolator = NumberMorphView.LinearInterpolator();
//        s0.interpolator = NumberMorphView.LinearInterpolator();
//        
//        NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(ViewController.updateTime), userInfo: nil, repeats: true);
//        
//    }
    
    // 更新时间
//    func updateTime() -> () {
//        let date = NSDate();
//        let components = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)?.components([NSCalendarUnit.Hour, NSCalendarUnit.Minute, NSCalendarUnit.Second], fromDate: date);
//        let hour = components?.hour ?? 0;
//        let minute = components?.minute ?? 0;
//        let second = components?.second ?? 0;
//        // 小时
//        if hour / 10 != h1.currentDigit || h1.currentDigit == 0 {
//            h1.nextDigit = hour / 10;
//        }
//        if hour % 10 != h0.currentDigit || h0.currentDigit == 0 {
//            h0.nextDigit = hour % 10;
//        }
//        // 分
//        if minute / 10 != m1.currentDigit || m1.currentDigit == 0 {
//            m1.nextDigit = minute / 10;
//        }
//        if minute % 10 != m0.currentDigit || m0.currentDigit == 0 {
//            m0.nextDigit = minute % 10;
//        }
//        // 秒
//        if second / 10 != s1.currentDigit || s1.currentDigit == 0 {
//            s1.nextDigit = second / 10;
//        }
//        if second % 10 != s0.currentDigit || s0.currentDigit == 0 {
//            s0.nextDigit = second % 10;
//        }
//    }
    
    // 请求“现在”数据
    func requestDataNow(info: String) ->() {
        let tLocation: TLocation = TLocation()
        let tNow: TNow = TNow()
        Alamofire.request(.GET, Constants.nowURL + info).responseJSON{ response in
            // 解析返回JSON
            if let JSON = response.result.value as? NSDictionary {
                if let results =  JSON["results"] as? NSArray {
                    for item in results {
                        if let jsonDic = item as? NSDictionary {
                            // 处理location
                            let location = jsonDic["location"] as! NSDictionary
                            tLocation.id = location["id"] as? String
                            tLocation.name = location["name"] as? String
                            tLocation.country = location["country"] as? String
                            tLocation.path = location["path"] as? String
                            tLocation.timezone = location["timezone"] as? String
                            tLocation.timezone_offset = location["timezone_offset"] as? String
                            // 处理now
                            let now = jsonDic["now"] as! NSDictionary
                            tNow.code = now["code"] as? String
                            tNow.temperature = now["temperature"] as? String
                            tNow.text = now["text"] as? String
                            // 处理last update
                            tNow.last_update = jsonDic["last_update"] as? String
                        }
                    }
                }
            }
            // 赋值
            self.wholeLocation = tLocation
            self.wholeNow = tNow
            self.drawUINow()
        }
    }
    
    // 请求“三天”数据
    func requestDataAll(info: String) ->() {
        var threeDaysInfo: Array<Tdaily> = Array<Tdaily>()
        Alamofire.request(.GET, Constants.threeDaysURL + info).responseJSON{ response in
            // 解析返回JSON
            if let JSON = response.result.value as? NSDictionary {
                if let results =  JSON["results"] as? NSArray {
                    for item in results {
                        if let jsonDic = item as? NSDictionary {
                            // 处理daily
                            let dailys = jsonDic["daily"] as! NSArray
                            for daily in dailys {
                                if let dailyJson = daily as? NSDictionary {
                                    let tdaily: Tdaily = Tdaily()
                                    tdaily.code_day = (dailyJson["code_day"] as? String)!
                                    tdaily.code_night = (dailyJson["code_night"] as? String)!
                                    tdaily.date = (dailyJson["date"] as? String)!
                                    tdaily.high = (dailyJson["high"] as? String)!
                                    tdaily.low = (dailyJson["low"] as? String)!
                                    tdaily.precip = (dailyJson["precip"] as? String)!
                                    tdaily.text_day = (dailyJson["text_day"] as? String)!
                                    tdaily.text_night = (dailyJson["text_night"] as? String)!
                                    tdaily.wind_direction = (dailyJson["wind_direction"] as? String)!
                                    tdaily.wind_direction_degree = (dailyJson["wind_direction_degree"] as? String)!
                                    tdaily.wind_scale = dailyJson["wind_scale"] as? String
                                    tdaily.wind_speed = (dailyJson["wind_speed"] as? String)!
                                    threeDaysInfo.append(tdaily)
                                }
                            }
                        }
                    }
                }
            }
            // 赋值
            self.wholeThreeDays = threeDaysInfo
            
            self.drawUIThreeDays()
        }
    }
    
    func drawUINow() -> () {

        // 定位地点
        addressLabel.text = wholeLocation.name
        
        // 定位图标
        let dingweiIconFrame = CGRect(x: self.view.bounds.width - 16 - 20, y: 20, width: 16, height: 16)
        let dingweiImageView = UIImageView(frame: dingweiIconFrame)
        dingweiImageView.image = UIImage(named: "dingwei")
        self.view.addSubview(dingweiImageView)
        
        // 天气图标
        mainWeatherImage.image = UIImage(named: self.wholeNow.code!)
        
        // 天气状态
        mainWeatherText.text = wholeNow.text
        
        // 温度
        mainWeatherTemp.text = wholeNow.temperature! + "°"
        
    }
    
    func drawUIThreeDays() -> () {
        
        let leftMargin: CGFloat = 10.0
        let rightMargin: CGFloat = 10.0
        
        // 今天的面板
        let firstDaysFrame = CGRect(x: 0, y: self.view.bounds.height - 160, width: self.view.bounds.width / 3, height: 110)
        let firstDaysView: SpringView = SpringView(frame: firstDaysFrame)
        // 1. 日期
        let firstDateLabelFrame = CGRect(x: 0, y: 0, width: self.view.bounds.width / 3, height: 15)
        let firstDateLabel = UILabel(frame: firstDateLabelFrame)
        firstDateLabel.text = "今天"
        firstDateLabel.textColor = UIColor.whiteColor()
        firstDateLabel.textAlignment = .Center
        firstDaysView.addSubview(firstDateLabel)
        // 2. 天气图标
        let firstIconFrame = CGRect(x: leftMargin, y: 20, width: (firstDaysView.frame.width - leftMargin - rightMargin) / 2, height: (firstDaysView.frame.width - leftMargin - rightMargin) / 2)
        let firstIconView = UIImageView(frame: firstIconFrame)
        firstIconView.image = UIImage(named: wholeThreeDays[0].code_day)
        firstDaysView.addSubview(firstIconView)
        // 3. 天气文字
        let firstWeatherTextFrame = CGRect(x: leftMargin + firstIconFrame.width, y: 20, width: (firstDaysView.frame.width - leftMargin - rightMargin) / 2, height: firstIconFrame.height / 2)
        let firstWeatherTextLabel = UILabel(frame: firstWeatherTextFrame)
        firstWeatherTextLabel.textColor = UIColor.whiteColor()
        firstWeatherTextLabel.textAlignment = .Center
        firstWeatherTextLabel.font = UIFont.systemFontOfSize(16)
        firstWeatherTextLabel.text = wholeThreeDays[0].text_day
        firstDaysView.addSubview(firstWeatherTextLabel)
        // 4. 温度数字
        let firstTemperatureTextFrame = CGRect(x: leftMargin + firstIconFrame.width, y: 20 + firstIconFrame.height / 2, width: (firstDaysView.frame.width - leftMargin - rightMargin) / 2, height: firstIconFrame.height / 2)
        let firstTemperatureTextLabel = UILabel(frame: firstTemperatureTextFrame)
        firstTemperatureTextLabel.textColor = UIColor.whiteColor()
        firstTemperatureTextLabel.textAlignment = .Center
        firstTemperatureTextLabel.font = UIFont.systemFontOfSize(14)
        firstTemperatureTextLabel.text = wholeThreeDays[0].low + " - " + wholeThreeDays[0].high
        firstDaysView.addSubview(firstTemperatureTextLabel)
        // 5. 降水概率
        let firstWaveLoadingFrame = CGRect(x: (firstDaysView.frame.width / 2 - 24), y: 20 + firstIconView.frame.height, width: 48, height: 48)
        let firstWaveLoadingIndicator: WaveLoadingIndicator = WaveLoadingIndicator(frame: firstWaveLoadingFrame)
        if (self.wholeThreeDays[0].precip != "") {
            firstWaveLoadingIndicator.progress = Double(self.wholeThreeDays[0].precip)! / 100
        } else {
            firstWaveLoadingIndicator.progress = 0.0
        }
        firstWaveLoadingIndicator.borderWidth = 1.5
        firstWaveLoadingIndicator.waveAmplitude = 3.2
        firstWaveLoadingIndicator.shapeModel = .shapeModelCircle
        //firstWaveLoadingIndicator.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        firstDaysView.addSubview(firstWaveLoadingIndicator)
        
        // 明天的面板
        let secondDaysFrame = CGRect(x: self.view.bounds.width / 3, y: self.view.bounds.height - 160, width: self.view.bounds.width / 3, height: 110)
        let secondDaysView: SpringView = SpringView(frame: secondDaysFrame)
        // 1. 日期
        let secondDataLabelFrame = CGRect(x: 0, y: 0, width: self.view.bounds.width / 3, height: 15)
        let secondDateLabel = UILabel(frame: secondDataLabelFrame)
        secondDateLabel.text = "明天"
        secondDateLabel.textColor = UIColor.whiteColor()
        secondDateLabel.textAlignment = .Center
        secondDaysView.addSubview(secondDateLabel)
        
        // 2. 天气图标
        let secondIconFrame = CGRect(x: leftMargin, y: 20, width: (secondDaysView.frame.width - leftMargin - rightMargin) / 2, height: (secondDaysView.frame.width - leftMargin - rightMargin) / 2)
        let secondIconView = UIImageView(frame: secondIconFrame)
        secondIconView.image = UIImage(named: wholeThreeDays[1].code_day)
        secondDaysView.addSubview(secondIconView)
        // 3. 天气文字
        let secondWeatherTextFrame = CGRect(x: leftMargin + secondIconFrame.width, y: 20, width: (secondDaysView.frame.width - leftMargin - rightMargin) / 2, height: secondIconFrame.height / 2)
        let secondWeatherTextLabel = UILabel(frame: secondWeatherTextFrame)
        secondWeatherTextLabel.textColor = UIColor.whiteColor()
        secondWeatherTextLabel.textAlignment = .Center
        secondWeatherTextLabel.text = wholeThreeDays[1].text_day
        secondDaysView.addSubview(secondWeatherTextLabel)
        // 4. 温度数字
        let secondTemperatureTextFrame = CGRect(x: leftMargin + secondIconFrame.width, y: 20 + secondIconFrame.height / 2, width: (secondDaysView.frame.width - leftMargin - rightMargin) / 2, height: secondIconFrame.height / 2)
        let secondTemperatureTextLabel = UILabel(frame: secondTemperatureTextFrame)
        secondTemperatureTextLabel.textColor = UIColor.whiteColor()
        secondTemperatureTextLabel.textAlignment = .Center
        secondTemperatureTextLabel.text = wholeThreeDays[1].low + " - " + wholeThreeDays[1].high
        secondDaysView.addSubview(secondTemperatureTextLabel)
        // 5. 降水概率
        let secondWaveLoadingFrame = CGRect(x: (secondDaysView.frame.width / 2 - 24), y: 20 + secondIconView.frame.height, width: 48, height: 48)
        let secondWaveLoadingIndicator: WaveLoadingIndicator = WaveLoadingIndicator(frame: secondWaveLoadingFrame)
        if (self.wholeThreeDays[0].precip != "") {
            secondWaveLoadingIndicator.progress = Double(self.wholeThreeDays[1].precip)! / 100
        } else {
            secondWaveLoadingIndicator.progress = 0.0
        }
        secondWaveLoadingIndicator.borderWidth = 1.5
        secondWaveLoadingIndicator.waveAmplitude = 3.2
        secondWaveLoadingIndicator.shapeModel = .shapeModelCircle
        secondDaysView.addSubview(secondWaveLoadingIndicator)
        
        
        // 后天的面板
        let thirdDaysFrame = CGRect(x: self.view.bounds.width * 2 / 3, y: self.view.bounds.height - 160, width: self.view.bounds.width / 3, height: 110)
        let thirdDaysView: SpringView = SpringView(frame: thirdDaysFrame)
        // 1. 日期
        let thirdDataLabelFrame = CGRect(x: 0, y: 0, width: self.view.bounds.width / 3, height: 15)
        let thirdDateLabel = UILabel(frame: thirdDataLabelFrame)
        thirdDateLabel.text = String(wholeThreeDays[2].date).componentsSeparatedByString("-")[1] + "月" + String(wholeThreeDays[2].date).componentsSeparatedByString("-")[2]
        thirdDateLabel.textColor = UIColor.whiteColor()
        thirdDateLabel.textAlignment = .Center
        thirdDaysView.addSubview(thirdDateLabel)
        // 2. 天气图标
        let thirdIconFrame = CGRect(x: leftMargin, y: 20, width: (thirdDaysView.frame.width - leftMargin - rightMargin) / 2, height: (thirdDaysView.frame.width - leftMargin - rightMargin) / 2)
        let thirdIconView = UIImageView(frame: thirdIconFrame)
        thirdIconView.image = UIImage(named: wholeThreeDays[2].code_day)
        thirdDaysView.addSubview(thirdIconView)
        // 3. 天气文字
        let thirdWeatherTextFrame = CGRect(x: leftMargin + thirdIconFrame.width, y: 20, width: (thirdDaysView.frame.width - leftMargin - rightMargin) / 2, height: thirdIconFrame.height / 2)
        let thirdWeatherTextLabel = UILabel(frame: thirdWeatherTextFrame)
        thirdWeatherTextLabel.textColor = UIColor.whiteColor()
        thirdWeatherTextLabel.textAlignment = .Center
        thirdWeatherTextLabel.text = wholeThreeDays[2].text_day
        thirdDaysView.addSubview(thirdWeatherTextLabel)
        // 4. 温度数字
        let thirdTemperatureTextFrame = CGRect(x: leftMargin + thirdIconFrame.width, y: 20 + thirdIconFrame.height / 2, width: (thirdDaysView.frame.width - leftMargin - rightMargin) / 2, height: thirdIconFrame.height / 2)
        let thirdTemperatureTextLabel = UILabel(frame: thirdTemperatureTextFrame)
        thirdTemperatureTextLabel.textColor = UIColor.whiteColor()
        thirdTemperatureTextLabel.textAlignment = .Center
        thirdTemperatureTextLabel.text = wholeThreeDays[2].low + " - " + wholeThreeDays[2].high
        thirdDaysView.addSubview(thirdTemperatureTextLabel)
        // 5. 降水概率
        let thirdWaveLoadingFrame = CGRect(x: (thirdDaysView.frame.width / 2 - 24), y: 20 + thirdIconView.frame.height, width: 48, height: 48)
        let thirdWaveLoadingIndicator: WaveLoadingIndicator = WaveLoadingIndicator(frame: thirdWaveLoadingFrame)
        if (self.wholeThreeDays[0].precip != "") {
            thirdWaveLoadingIndicator.progress = Double(self.wholeThreeDays[2].precip)! / 100
        } else {
            thirdWaveLoadingIndicator.progress = 0.0
        }
        thirdWaveLoadingIndicator.borderWidth = 1.5
        thirdWaveLoadingIndicator.waveAmplitude = 3.2
        thirdWaveLoadingIndicator.shapeModel = .shapeModelCircle
        //firstWaveLoadingIndicator.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        thirdDaysView.addSubview(thirdWaveLoadingIndicator)

        
        
        self.view.addSubview(firstDaysView)
        self.view.addSubview(secondDaysView)
        self.view.addSubview(thirdDaysView)
        
        firstDaysView.animation = "zoomIn"
        firstDaysView.curve = "easeIn"
        firstDaysView.force = 2.5
        firstDaysView.duration = 1.5
        firstDaysView.animate()
        
        secondDaysView.animation = "zoomIn"
        secondDaysView.curve = "easeIn"
        secondDaysView.force = 2.5
        secondDaysView.duration = 2.0
        secondDaysView.animate()
        
        thirdDaysView.animation = "zoomIn"
        thirdDaysView.curve = "easeIn"
        thirdDaysView.force = 2.5
        thirdDaysView.duration = 2.5
        thirdDaysView.animate()
        
        
//        // Color Declarations
//        let fillColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
//        
//        // Group 2
//        // Group 3
//        // Bezier Drawing
//        let bezierPath = UIBezierPath()
//        bezierPath.moveToPoint(CGPoint(x: 42.13, y: 0.7))
//        bezierPath.addCurveToPoint(CGPoint(x: 37.87, y: 0.7), controlPoint1: CGPoint(x: 40.95, y: -0.23), controlPoint2: CGPoint(x: 39.05, y: -0.23))
//        bezierPath.addCurveToPoint(CGPoint(x: 0.13, y: 48.13), controlPoint1: CGPoint(x: 36.33, y: 1.93), controlPoint2: CGPoint(x: 0.13, y: 31.05))
//        bezierPath.addCurveToPoint(CGPoint(x: 40, y: 80), controlPoint1: CGPoint(x: 0.13, y: 65.7), controlPoint2: CGPoint(x: 18.02, y: 80))
//        bezierPath.addCurveToPoint(CGPoint(x: 79.87, y: 48.13), controlPoint1: CGPoint(x: 61.98, y: 80), controlPoint2: CGPoint(x: 79.87, y: 65.7))
//        bezierPath.addCurveToPoint(CGPoint(x: 42.13, y: 0.7), controlPoint1: CGPoint(x: 79.87, y: 31.05), controlPoint2: CGPoint(x: 43.67, y: 1.93))
//        bezierPath.addLineToPoint(CGPoint(x: 42.13, y: 0.7))
//        bezierPath.closePath()
//        bezierPath.moveToPoint(CGPoint(x: 40, y: 75.19))
//        bezierPath.addCurveToPoint(CGPoint(x: 6.15, y: 48.13), controlPoint1: CGPoint(x: 21.34, y: 75.19), controlPoint2: CGPoint(x: 6.15, y: 63.05))
//        bezierPath.addCurveToPoint(CGPoint(x: 40, y: 5.85), controlPoint1: CGPoint(x: 6.15, y: 36.41), controlPoint2: CGPoint(x: 28.88, y: 15.09))
//        bezierPath.addCurveToPoint(CGPoint(x: 73.85, y: 48.13), controlPoint1: CGPoint(x: 51.13, y: 15.09), controlPoint2: CGPoint(x: 73.85, y: 36.41))
//        bezierPath.addCurveToPoint(CGPoint(x: 40, y: 75.19), controlPoint1: CGPoint(x: 73.85, y: 63.05), controlPoint2: CGPoint(x: 58.66, y: 75.19))
//        bezierPath.addLineToPoint(CGPoint(x: 40, y: 75.19))
//        bezierPath.closePath()
//        bezierPath.moveToPoint(CGPoint(x: 63.1, y: 46.87))
//        bezierPath.addCurveToPoint(CGPoint(x: 59.77, y: 48.99), controlPoint1: CGPoint(x: 61.44, y: 46.71), controlPoint2: CGPoint(x: 59.95, y: 47.67))
//        bezierPath.addCurveToPoint(CGPoint(x: 42.89, y: 65.06), controlPoint1: CGPoint(x: 58.69, y: 56.59), controlPoint2: CGPoint(x: 52.07, y: 62.89))
//        bezierPath.addCurveToPoint(CGPoint(x: 40.86, y: 68.05), controlPoint1: CGPoint(x: 41.3, y: 65.44), controlPoint2: CGPoint(x: 40.39, y: 66.78))
//        bezierPath.addCurveToPoint(CGPoint(x: 43.75, y: 69.78), controlPoint1: CGPoint(x: 41.25, y: 69.1), controlPoint2: CGPoint(x: 42.45, y: 69.78))
//        bezierPath.addCurveToPoint(CGPoint(x: 44.6, y: 69.68), controlPoint1: CGPoint(x: 44.03, y: 69.78), controlPoint2: CGPoint(x: 44.32, y: 69.74))
//        bezierPath.addCurveToPoint(CGPoint(x: 65.75, y: 49.53), controlPoint1: CGPoint(x: 56.1, y: 66.96), controlPoint2: CGPoint(x: 64.4, y: 59.06))
//        bezierPath.addCurveToPoint(CGPoint(x: 63.1, y: 46.87), controlPoint1: CGPoint(x: 65.94, y: 48.21), controlPoint2: CGPoint(x: 64.75, y: 47.02))
//        bezierPath.addLineToPoint(CGPoint(x: 63.1, y: 46.87))
//        bezierPath.closePath()
//        bezierPath.miterLimit = 4;
//        
//        fillColor.setFill()
//        bezierPath.fill()
//        
//        let myPath = bezierPath.CGPath
//       
//        var loader = WavesLoader.createLoaderWithPath(path: myPath)
//        loader.loaderColor = UIColor.redColor()
//        loader.showLoader()
        
        
    }
}

